<template>
  <div class="add_update_building">
    <!-- 新增区域 -->
    <el-dialog
      width="500px"
      custom-class="customWidth"
      center
      :before-close="closeDialog"
      title="新增区域"
      :close-on-click-modal="false"
      :visible.sync="addDialogFormVisible"
    >
      <el-form
        :model="addataForm"
        :rules="addataRule"
        ref="addataForm"
        @keyup.enter.native="addataFormSubmit()"
        label-width="100px"
      >
        <el-form-item label="上级区域" prop="superiorAreaGuid">
          <el-col :span="15">
            <el-select
              v-model="addataForm.superiorAreaGuid"
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in superiorAreaGuidlist"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="区域名称" prop="areaName">
          <el-col :span="15">
            <el-input maxlength="20" v-model="addataForm.areaName" placeholder="区域名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="区域负责人" prop="regionprincipalarr">
          <el-col :span="15">
            <el-select
              v-model="addataForm.regionprincipalarr"
              multiple
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in principalarr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-col :span="15">
            <el-input v-model="addataForm.remark" placeholder="备注" type="textarea"></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addvisible()">取消</el-button>
        <el-button type="primary" @click="addataFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 修改区域 -->
    <el-dialog
      width="500px"
      custom-class="customWidth"
      center
      title="修改区域"
      :close-on-click-modal="false"
      :before-close="editcloseDialog"
      :visible.sync="editDialogFormVisible"
    >
      <el-form
        :model="editataForm"
        :rules="editataRule"
        ref="editataForm"
        @keyup.enter.native="editataFormSubmit()"
        label-width="100px"
      >
        <el-form-item label="上级区域" prop="superiorAreaGuid">
          <el-col :span="15">
            <el-select
              v-model="editataForm.superiorAreaGuid"
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in editsuperiorAreaGuidlist"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="区域名称" prop="areaName">
          <el-col :span="15">
            <el-input v-model="editataForm.areaName" placeholder="区域名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="区域负责人" prop="regionprincipalarr">
          <el-col :span="15">
            <el-select
              v-model="editataForm.regionprincipalarr"
              multiple
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in principalarr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editvisible()">取消</el-button>
        <el-button type="primary" @click="editataFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 新增楼栋 -->
    <el-dialog
      width="900px"
      custom-class="customWidth"
      center
      title="新增楼栋"
      :close-on-click-modal="false"
      :before-close="closeDialogbuilding"
      :visible.sync="addbuildingDialogFormVisible"
    >
      <!-- 新增网关 -->
      <el-dialog
        width="400px"
        title="添加网关"
        :visible.sync="innerVisible"
        :before-close="controllercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form
          :model="controllerBuildingRequestList"
          :rules="controllerBuildingRequestListRule"
          ref="controllerBuildingRequestList"
          label-width="88px"
          v-if="innerVisible"
        >
          <el-form-item label="网关类型" prop="controllerType">
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.controllerType"
                placeholder="请选择"
                size="mini"
                @change="handleChage"
              >
                <el-option
                  v-for="item in controllerTypeoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
              <el-form-item label="设备型号" prop="controllerModel">
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.controllerModel"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in terminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="网关名称" prop="controllerName">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.controllerName"
                placeholder="网关名称"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item
            label="信道号"
            prop="channel"
            v-if="controllerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.channel"
                placeholder="信道号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="ip地址" prop="ip">
            <el-col :span="20">
              <el-input v-model="controllerBuildingRequestList.ip" placeholder="ip地址" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="端口" prop="port">
            <el-col :span="20">
              <el-input v-model="controllerBuildingRequestList.port" placeholder="端口" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="安装位置" prop="position">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.position"
                placeholder="安装位置"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
      
          <el-form-item
            label="无线功率"
            prop="wirelessPower"
            v-if="controllerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.wirelessPower"
                placeholder="请选择"
                size="mini"
              >
                <el-option v-for="item in 3" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <!-- <el-form-item label="控制器版本" prop="firmwareVersion">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.firmwareVersion"
                placeholder="请输入控制器版本号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>-->
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="controllerBuildingRequestList.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="controlladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="controlladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <!-- 编辑网关 -->
      <el-dialog
        width="400px"
        title="编辑网关"
        :visible.sync="addinnerVisible"
        :before-close="addcontrollercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form
          :model="addcontrollerBuildingRequestList"
          :rules="addcontrollerBuildingRequestListRule"
          ref="addcontrollerBuildingRequestList"
          label-width="88px"
        >
          <el-form-item label="网关类型" prop="controllerType">
            <el-col :span="20">
              <el-select
                v-model="addcontrollerBuildingRequestList.controllerType"
                placeholder="请选择"
                size="mini"
                @change="handleChage"
                disabled
              >
                <el-option
                  v-for="item in controllerTypeoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
             <el-form-item label="设备型号" prop="controllerModel">
            <el-col :span="20">
              <el-select
                v-model="addcontrollerBuildingRequestList.controllerModel"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in terminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="网关名称" prop="controllerName">
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.controllerName"
                placeholder="网关名称"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item
            label="信道号"
            prop="channel"
            v-if="addcontrollerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.channel"
                placeholder="信道号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="ip地址" prop="ip">
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.ip"
                placeholder="ip地址"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="端口" prop="port">
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.port"
                placeholder="端口"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="安装位置" prop="position">
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.position"
                placeholder="安装位置"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
       
          <el-form-item
            label="无线功率"
            prop="wirelessPower"
            v-if="addcontrollerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-select
                v-model="addcontrollerBuildingRequestList.wirelessPower"
                placeholder="请选择"
                size="mini"
              >
                <el-option v-for="item in 3" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <!-- <el-form-item label="控制器版本" prop="firmwareVersion">
            <el-col :span="20">
              <el-input
                v-model="addcontrollerBuildingRequestList.firmwareVersion"
                placeholder="请输入控制器版本号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>-->
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="addcontrollerBuildingRequestList.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="addcontrolladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="addcontrolladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <!-- 新增中继 -->
      <el-dialog
        width="400px"
        :title="Ztitle"
        :visible.sync="repeaterinnerVisible"
        :before-close="repeatercontrollercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form :model="crepeaterid" :rules="crepeateridrule" ref="crepeaterid" label-width="80px">
          <el-form-item label="中继编号" prop="repeaterid">
            <el-col :span="20">
              <el-input v-model="crepeaterid.repeaterid" placeholder="中继编号" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="中继名称" prop="terminalName">
            <el-col :span="20">
              <el-input v-model="crepeaterid.terminalName" placeholder="中继名称" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="设备型号" prop="terminalModel">
            <el-col :span="20">
              <el-select v-model="crepeaterid.terminalModel" placeholder="请选择" size="mini">
                <el-option
                  v-for="item in repeaterTerminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="crepeaterid.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="repeatercontrolladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="repeatercontrolladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <el-form
        :model="addbuilding"
        :rules="addbuildingRule"
        ref="addbuilding"
        @keyup.enter.native="addbuildingSubmit()"
        label-width="100px"
      >
        <el-form-item label="楼栋名称" prop="buildingName">
          <el-col :span="15">
            <el-input v-model="addbuilding.buildingName" placeholder="楼栋名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="楼栋编号" prop="buildingCode">
          <el-col :span="15">
            <el-input v-model.number="addbuilding.buildingCode" placeholder="楼栋编号" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="楼层数" prop="floors">
          <el-col :span="15">
            <el-input v-model.number="addbuilding.floors" placeholder="楼层数" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="所属区域" prop="areaGuid">
          <el-col :span="15">
            <el-select
              v-model="addbuilding.areaGuid"
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in buildingsuperiorAreaGuidlist"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="区域负责人" prop="regionprincipalarr">
          <el-col :span="15">
            <el-select
              v-model="addbuilding.regionprincipalarr"
              multiple
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in principalarr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="网关操作">
          <el-col :span="15">
            <el-button type="primary" @click="addgateway" size="mini">添加网关</el-button>
          </el-col>
        </el-form-item>
        <el-table
          :data="controllerBuildingRequestListArr"
          border
          highlight-current-row
          @expand-change="expandSelect"
          :row-class-name="tableRowClassName"
          :expand-row-keys="expands"
          :row-key="getRowKeys"
          style="width: 100%"
          :header-cell-style="headFirst"
        >
          <el-table-column type="expand" class="zhongji_css">
            <el-table :data="relaylist" border style="width: 100%">
              <el-table-column prop="isUse" label="是否启用">
                <template slot-scope="scope">
                  {{
                  scope.row.isUse == 0 ? "未启用" : "已启用"
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="terminalModel" label="型号">
                <template slot-scope="scope">
                  {{
                  scope.row.terminalModel
                  | controllerModelType(repeaterTerminaloption)
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="terminalName" label="中继名称"></el-table-column>
              <el-table-column prop="terminalCode" label="中继编号"></el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="mini"
                    @click="edittegateway(scope.row, scope.$index)"
                  >编辑</el-button>
                  <el-button
                    type="text"
                    style="color: red"
                    size="mini"
                    @click="repeatereletegateway(scope.row, scope.$index)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-table-column>
          <el-table-column prop="isUse" label="是否启用">
            <template slot-scope="scope">
              {{
              scope.row.isUse == 0 ? "未启用" : "已启用"
              }}
            </template>
          </el-table-column>
          <el-table-column prop="controllerModel" label="型号">
            <template slot-scope="scope">
              {{
              scope.row.controllerModel | controllerModelType(terminaloptionA)
              }}
            </template>
          </el-table-column>
          <el-table-column prop="controllerName" label="网关名称" width="100"></el-table-column>
          <el-table-column prop="channel" label="信道"></el-table-column>
          <el-table-column prop="ip" label="ip"></el-table-column>
          <el-table-column prop="port" label="端口"></el-table-column>
          <el-table-column prop="position" label="安装位置"></el-table-column>
          <el-table-column width="160" label="操作">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                @click="repeateraddgateway(scope.row, scope.$index)"
                v-if="
                scope.row.controllerType == 1 && 
                  !(
                    scope.row.controllerModel == 93 ||
                    scope.row.controllerModel == 95 ||
                    scope.row.controllerModel == 97
                  ) 
                "
              >添加中继</el-button>
              <el-button
                type="text"
                size="mini"
                @click="addrepeateraddgateway(scope.row, scope.$index)"
              >编辑</el-button>
              <el-button
                type="text"
                size="mini"
                style="color: red"
                @click="deletegateway(scope.$index)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addbuildingvisible()">取消</el-button>
        <el-button type="primary" @click="addbuildingFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
    <!-- 修改楼栋 -->
    <el-dialog
      width="900px"
      custom-class="customWidth"
      center
      title="修改楼栋"
      :close-on-click-modal="false"
      :before-close="editcloseDialogbuilding"
      :visible.sync="editbuildingDialogFormVisible"
    >
      <!-- 新增网关 -->
      <el-dialog
        width="400px"
        title="添加网关"
        :visible.sync="innerVisible"
        :before-close="controllercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form
          :model="controllerBuildingRequestList"
          :rules="controllerBuildingRequestListRule"
          ref="controllerBuildingRequestList"
          label-width="100px"
          v-if="innerVisible"
        >
          <el-form-item label="网关类型" prop="controllerType">
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.controllerType"
                placeholder="请选择"
                size="mini"
                @change="handleChage"
              >
                <el-option
                  v-for="item in controllerTypeoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
             <el-form-item label="设备型号" prop="controllerModel">
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.controllerModel"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in terminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="网关名称" prop="controllerName">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.controllerName"
                placeholder="网关名称"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item
            label="信道号"
            prop="channel"
            v-if="controllerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.channel"
                placeholder="信道号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="ip地址" prop="ip">
            <el-col :span="20">
              <el-input v-model="controllerBuildingRequestList.ip" placeholder="ip地址" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="端口" prop="port">
            <el-col :span="20">
              <el-input v-model="controllerBuildingRequestList.port" placeholder="端口" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="安装位置" prop="position">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.position"
                placeholder="安装位置"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
       
          <el-form-item
            label="无线功率"
            prop="wirelessPower"
            v-if="controllerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-select
                v-model="controllerBuildingRequestList.wirelessPower"
                placeholder="请选择"
                size="mini"
              >
                <el-option v-for="item in 3" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <!-- <el-form-item label="控制器版本" prop="firmwareVersion">
            <el-col :span="20">
              <el-input
                v-model="controllerBuildingRequestList.firmwareVersion"
                placeholder="请输入控制器版本号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>-->
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="controllerBuildingRequestList.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="controlladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="controlladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <!-- 编辑网关 -->
      <el-dialog
        width="400px"
        title="编辑网关"
        :visible.sync="eidtinnerVisible"
        :before-close="eidtcontrollercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form
          :model="editcontrollerBuildingRequestList"
          :rules="editcontrollerBuildingRequestListRule"
          ref="editcontrollerBuildingRequestList"
          label-width="100px"
        >
          <el-form-item label="网关类型" prop="controllerType">
            <el-col :span="20">
              <el-select
                v-model="editcontrollerBuildingRequestList.controllerType"
                placeholder="请选择"
                size="mini"
                @change="handleChage"
                disabled
              >
                <el-option
                  v-for="item in controllerTypeoptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
              <el-form-item label="设备型号" prop="controllerModel">
            <el-col :span="20">
              <el-select
                v-model="editcontrollerBuildingRequestList.controllerModel"
                placeholder="请选择"
                size="mini"
              >
                <el-option
                  v-for="item in terminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="网关名称" prop="controllerName">
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.controllerName"
                placeholder="网关名称"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item
            label="信道号"
            prop="channel"
            v-if="editcontrollerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.channel"
                placeholder="信道号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="ip地址" prop="ip">
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.ip"
                placeholder="ip地址"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="端口" prop="port">
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.port"
                placeholder="端口"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="安装位置" prop="position">
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.position"
                placeholder="安装位置"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
      
          <el-form-item
            label="无线功率"
            prop="wirelessPower"
            v-if="editcontrollerBuildingRequestList.controllerType == 1"
          >
            <el-col :span="20">
              <el-select
                v-model="editcontrollerBuildingRequestList.wirelessPower"
                placeholder="请选择"
                size="mini"
              >
                <el-option v-for="item in 3" :key="item" :label="item" :value="item"></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="控制器版本" prop="firmwareVersion">
            <el-col :span="20">
              <el-input
                v-model="editcontrollerBuildingRequestList.firmwareVersion"
                placeholder="请输入控制器版本号"
                size="mini"
              ></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="editcontrollerBuildingRequestList.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="eidtcontrolladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="eidtcontrolladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <!--中继 -->
      <el-dialog
        width="400px"
        :title="Ztitle"
        :visible.sync="repeaterinnerVisible"
        :before-close="repeatercontrollercloseDialog"
        append-to-body
        :close-on-click-modal="false"
      >
        <el-form :model="crepeaterid" :rules="crepeateridrule" ref="crepeaterid" label-width="80px">
          <el-form-item label="中继编号" prop="repeaterid">
            <el-col :span="20">
              <el-input v-model="crepeaterid.repeaterid" placeholder="中继编号" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="中继名称" prop="terminalName">
            <el-col :span="20">
              <el-input v-model="crepeaterid.terminalName" placeholder="中继名称" size="mini"></el-input>
            </el-col>
          </el-form-item>
          <el-form-item label="设备型号" prop="terminalModel">
            <el-col :span="20">
              <el-select v-model="crepeaterid.terminalModel" placeholder="请选择" size="mini">
                <el-option
                  v-for="item in repeaterTerminaloption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-col>
          </el-form-item>
          <el-form-item label="是否启用" prop="isUse">
            <el-col :span="20">
              <el-checkbox v-model="crepeaterid.isUse"></el-checkbox>
            </el-col>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="repeatercontrolladdbuildingvisible()">取消</el-button>
          <el-button type="primary" @click="repeatercontrolladdbuildingFormSubmit()">确定</el-button>
        </span>
      </el-dialog>
      <el-form
        :model="eidtbuilding"
        :rules="eidtbuildingRule"
        ref="eidtbuilding"
        @keyup.enter.native="eidtbuildingSubmit()"
        label-width="100px"
      >
        <el-form-item label="楼栋名称" prop="buildingName">
          <el-col :span="15">
            <el-input v-model="eidtbuilding.buildingName" placeholder="楼栋名称" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="楼栋编号" prop="buildingCode">
          <el-col :span="15">
            <el-input v-model.number="eidtbuilding.buildingCode" placeholder="楼栋编号" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="楼层数" prop="floors">
          <el-col :span="15">
            <el-input v-model.number="eidtbuilding.floors" placeholder="楼层数" size="mini"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="所属区域" prop="areaGuid">
          <el-col :span="15">
            <el-select
              v-model="eidtbuilding.areaGuid"
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in editbuildingsuperiorAreaGuidlist"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="区域负责人" prop="regionprincipalarr">
          <el-col :span="15">
            <el-select
              v-model="eidtbuilding.regionprincipalarr"
              multiple
              clearable
              placeholder="请选择"
              style="width: 100%"
              size="mini"
            >
              <el-option
                v-for="item in principalarr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-col>
        </el-form-item>
        <el-form-item label="网关操作">
          <el-col :span="10">
            <el-button type="primary" @click="addgateway" size="mini">添加网关</el-button>
          </el-col>
        </el-form-item>
        <el-table
          :data="controllerBuildingRequestListArr"
          border
          highlight-current-row
          @expand-change="expandSelect"
          :row-class-name="tableRowClassName"
          :expand-row-keys="expands"
          :row-key="getRowKeys"
          style="width: 100%"
          :header-cell-style="headFirst"
        >
          <el-table-column type="expand">
            <el-table :data="relaylist" border style="width: 100%">
              <el-table-column prop="isUse" label="是否启用">
                <template slot-scope="scope">
                  {{
                  scope.row.isUse == 0 ? "未启用" : "已启用"
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="terminalModel" label="型号">
                <template slot-scope="scope">
                  {{
                  scope.row.terminalModel | ModelType()
                  }}
                </template>
              </el-table-column>
              <el-table-column prop="terminalName" label="中继名称"></el-table-column>
              <el-table-column prop="terminalCode" label="中继编号"></el-table-column>
              <el-table-column width="160" label="操作">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    size="mini"
                    @click="edittegateway(scope.row, scope.$index)"
                  >编辑</el-button>
                  <el-button
                    type="text"
                    size="mini"
                    style="color: red"
                    @click="repeatereletegateway(scope.row, scope.$index)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-table-column>
          <el-table-column prop="isUse" label="是否启用">
            <template slot-scope="scope">
              {{
              scope.row.isUse == 0 ? "未启用" : "已启用"
              }}
            </template>
          </el-table-column>
          <el-table-column prop="controllerModel" label="型号">
            <template slot-scope="scope">
              {{
              scope.row.controllerModel | controllerModelType(terminaloptionA)
              }}
            </template>
          </el-table-column>
          <el-table-column prop="controllerName" label="控制器名称" min-width="100"></el-table-column>
          <el-table-column prop="channel" label="信道"></el-table-column>
          <el-table-column prop="ip" label="ip"></el-table-column>
          <el-table-column prop="port" label="端口"></el-table-column>
          <el-table-column prop="position" label="安装位置"></el-table-column>
          <el-table-column width="160" label="操作">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                @click="repeateraddgateway(scope.row, scope.$index)"
                v-if="
                scope.row.controllerType == 1 && 
                  !(
                    scope.row.controllerModel == 93 ||
                    scope.row.controllerModel == 95 ||
                    scope.row.controllerModel == 97
                  ) 
                "
              >添加中继</el-button>
              <el-button
                type="text"
                size="mini"
                @click="editrepeateraddgateway(scope.row, scope.$index)"
              >编辑</el-button>
              <el-button
                type="text"
                size="mini"
                style="color: red"
                @click="editdeletegateway(scope.$index)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="eidtbuildingvisible()">取消</el-button>
        <el-button type="primary" @click="eidtbuildingFormSubmit()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    // 楼栋编号
    let checkbuildingNumber = (rule, value, callback) => {
      // let floorsReg = /^[0-6]?[0-9]{1}$/;
      if (value == '') {
        callback(new Error('楼栋编号不能为空！'))
      } else if (value > 64) {
        callback(new Error('楼栋编号需小于64'))
      } else {
        callback()
      }
    }
    // /^(?:[1-9]?\d|99)$/
    let checkbuildingfloor = (rule, value, callback) => {
      let floorsReg = /^(?:[1-9]?\d|99)$/
      if (value == '') {
        callback(new Error('楼层不能为空！'))
      } else if (!floorsReg.test(value)) {
        callback(new Error('楼层格式错误！'))
      } else {
        callback()
      }
    }

    // ip验证规则
    let ipPort = (rule, value, callback) => {
      let portReg = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/
      if (!portReg.test(value)) {
        callback(new Error('ip格式错误！'))
      } else {
        callback()
      }
    }
    ////^([1-9]\d{0,2}|[1-4]\d{3}|5000)$/
    //网关端口检验
    let checkport = (rule, value, callback) => {
      let portReg = /^[1-9]$|(^[1-9][0-9]$)|(^[1-9][0-9][0-9]$)|(^[1-9][0-9][0-9][0-9]$)|(^[1-6][0-5][0-5][0-3][0-5]$)/
      if (value == '') {
        callback(new Error('端口不能为空'))
      } else if (!portReg.test(value)) {
        callback(new Error('端口格式错误！'))
      } else {
        callback()
      }
    }
    //中继
    let checkrepeaterid = (rule, value, callback) => {
      let repeateridReg = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|[1-9])$/
      if (value == '') {
        callback(new Error('中继不能为空'))
      } else if (!repeateridReg.test(value)) {
        callback(new Error('中继格式错误！'))
      } else {
        callback()
      }
    }
    return {
      // 当前编辑状态
      isEdit: false,
      // 当前需要编辑的中继索引
      Zindex: '',
      // 当前中继弹框名称
      Ztitle: '添加中继',
      // 当前展开数据
      expandRow: [],
      // 所有型号
      terminaloptionA: [],
      // 网关设备型号
      terminaloption: [],
      // 网关类型
      controllerTypeoptions: [
        {
          value: 1,
          label: '无线网关'
        },
        {
          value: 2,
          label: '有线网关'
        }
      ],
      expands: [],
      getRowKeys(row) {
        return row.index
      },
      //回调id
      callbackid: '',
      //网关索引
      gatewayindex: '',
      //网关弹窗
      innerVisible: false,
      eidtinnerVisible: false,
      addinnerVisible: false,

      //中继
      repeaterinnerVisible: false,
      controllerindex: 0,
      // 中继型号
      repeaterTerminaloption: [],
      //中继编号
      crepeaterid: {
        repeaterid: '',
        terminalName: '',
        terminalModel: '',
        isUse: true
      },
      //网关信息
      controllerBuildingRequestList: {
        // 网关类型
        controllerType: 1,
        //信道
        channel: '',
        //控制器名称
        controllerName: '',
        ip: '',
        //端口
        port: 4001,
        //安装位置
        position: '',
        controllerModel: '',
        wirelessPower: '3',
        firmwareVersion: '',
        isUse: true
      },
      //新增楼栋编辑网关信息
      addcontrollerBuildingRequestList: {
        // 网关类型
        controllerType: 1,
        channel: '',
        controllerName: '',
        ip: '',
        port: 4001,
        controllerGuid: '',
        position: '',
        controllerModel: '',
        wirelessPower: '3',
        firmwareVersion: '',
        isUse: true
      },
      //编辑网关信息
      editcontrollerBuildingRequestList: {
        // 网关类型
        controllerType: 1,
        channel: '',
        controllerName: '',
        ip: '',
        port: '',
        controllerGuid: '',
        position: '',
        controllerModel: '',
        wirelessPower: '3',
        firmwareVersion: '',
        isUse: true
      },
      //网关所有信息
      controllerBuildingRequestListArr: [],
      //对应中继信息
      relaylist: [],
      controllerBuildingRequestListRule: {
        channel: [{ required: true, message: '信道不能为空', trigger: 'blur' }],
        controllerName: [
          { required: true, message: '控制器名称不能为空', trigger: 'blur' }
        ],
        ip: [{ required: true, message: 'ip不能为空', trigger: 'blur' },{ required: true, validator: ipPort, trigger: 'blur' }],
        port: [{ required: true, validator: checkport, trigger: 'blur' }],
        controllerModel: [
          { required: true, message: '网关型号不能为空', trigger: 'blur' }
        ]
      },
      editcontrollerBuildingRequestListRule: {
        channel: [{ required: true, message: '信道不能为空', trigger: 'blur' }],
        controllerName: [
          { required: true, message: '控制器名称不能为空', trigger: 'blur' }
        ],
        ip: [{ required: true, message: 'ip不能为空', trigger: 'blur' },{ required: true, validator: ipPort, trigger: 'blur' }],
        port: [{ required: true, validator: checkport, trigger: 'blur' }],
        controllerModel: [
          { required: true, message: '网关型号不能为空', trigger: 'blur' }
        ]
      },
      addcontrollerBuildingRequestListRule: {
        channel: [{ required: true, message: '信道不能为空', trigger: 'blur' }],
        controllerName: [
          { required: true, message: '控制器名称不能为空', trigger: 'blur' }
        ],
        ip: [{ required: true, message: 'ip不能为空', trigger: 'blur' },{ required: true, validator: ipPort, trigger: 'blur' }],
        port: [{ required: true, validator: checkport, trigger: 'blur' }],
        controllerModel: [
          { required: true, message: '网关型号不能为空', trigger: 'blur' }
        ]
      },
      crepeateridrule: {
        repeaterid: [
          { required: true, validator: checkrepeaterid, trigger: 'blur' }
        ],
        terminalName: [
          { required: true, message: '中继名称不能为空', trigger: 'blur' }
        ],
        terminalModel: [
          { required: true, message: '设备型号不能为空', trigger: 'blur' }
        ]
      },

      editbuildingGuid: '',
      //区域新增
      addDialogFormVisible: false,
      editDialogFormVisible: false,
      // 楼栋新增
      addbuildingDialogFormVisible: false,
      editbuildingDialogFormVisible: false,
      //新增房间
      addroomDialogFormVisible: false,

      // 所有区域
      superiorAreaGuidlist: [],
      // 修改区域
      editsuperiorAreaGuidlist: [],
      //楼栋区域
      buildingsuperiorAreaGuidlist: [],
      editbuildingsuperiorAreaGuidlist: [],
      addataForm: {
        areaName: '',
        remark: '',
        superiorAreaGuid: '',
        regionprincipalarr: []
      },
      editataForm: {
        areaGuid: '',
        areaName: '',
        superiorAreaGuid: '',
        unitGuid: '',
        regionprincipalarr: []
      },
      //楼栋
      addbuilding: {
        buildingCode: '',
        buildingName: '',
        floors: '',
        areaGuid: '',
        regionprincipalarr: []
      },
      eidtbuilding: {
        buildingCode: '',
        buildingName: '',
        floors: '',
        areaGuid: '',
        buildingGuid: '',
        regionprincipalarr: []
      },
      //校验规则
      addataRule: {
        areaName: [
          { required: true, message: '区域名不能为空', trigger: 'blur' }
        ]
      },
      editataRule: {
        areaName: [
          { required: true, message: '区域名不能为空', trigger: 'blur' }
        ]
      },
      addbuildingRule: {
        floors: [
          { required: true, validator: checkbuildingfloor, trigger: 'blur' }
        ],
        buildingName: [
          { required: true, message: '楼栋名不能为空', trigger: 'blur' }
        ],
        buildingCode: [
          { required: true, message: '楼栋编号不能为空', trigger: 'blur' },
          { required: true, validator: checkbuildingNumber, trigger: 'blur' }
        ],
        areaGuid: [
          {
            required: true,
            message: '请选择区域',
            trigger: ['blur', 'change']
          }
        ]
      },
      eidtbuildingRule: {
        floors: [
          { required: true, validator: checkbuildingfloor, trigger: 'blur' }
        ],
        buildingName: [
          { required: true, message: '楼栋名不能为空', trigger: 'blur' }
        ],
        buildingCode: [
          { required: true, message: '楼栋编号不能为空', trigger: 'blur' },
          { required: true, validator: checkbuildingNumber, trigger: 'blur' }
        ],
        areaGuid: [
          {
            required: true,
            message: '请选择区域',
            trigger: ['blur', 'change']
          }
        ]
      },
      addroomataRule: {}
    }
  },
  props: ['unitGuid', 'arealsit', 'principalarr'],
  mounted() {
    // console.log(this.arealsit)
  },
  created() {
    this.userGuidList = sessionStorage.getItem('administrator')
    this.terminalselect(1)
    this.terminalselect(5)
    // this.doorterminalselect(true)
    // this.repeaterTerminalselect();
  },
  filters: {
    controllerModelType(val, terminaloption) {
      let label
      terminaloption.map(item => {
        if (item.value == val) {
          label = item.label
        }
      })
      return label
    },
    ModelType(val) {
      let arr = [
        {
          value: 110,
          label: 'WE1600'
        },
        {
          value: 111,
          label: 'WE1611'
        },
        {
          value: 112,
          label: 'WE1620'
        }
      ]
      let label
      arr.map(item => {
        if (item.value == val) {
          label = item.label
        }
      })
      return label
    }
  },
  methods: {
    // 根据网关类型，改变设备型号
    handleChage(val) {
      console.log(this.terminaloptionA)
      this.terminaloption = []
      this.controllerBuildingRequestList.controllerModel = ''
      if (val == 1) {
        this.terminalselect(1)
      } else if (val == 2) {
        this.terminalselect(2)
      }
    },
    // 有线设备型号
    doorterminalselect(type) {
      this.$http({
        url: this.$http.adornUrl('/terminal/terminal-model-select'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            terminalType: 21,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          let Arr = data.messageContent || []
          for (var i = 0; i < Arr.length; i++) {
            var itemObj = {
              label: Arr[i].modelName,
              value: Arr[i].modelId,
              type: 21
            }
            if (type) {
              this.terminaloptionA.push(itemObj)
            } else {
              this.terminaloption.push(itemObj)
            }
          }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 网关设备型号
    terminalselect(type) {
      this.$http({
        url: this.$http.adornUrl('/terminal/controller-model-select'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            terminalType: type,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data)
        if (data.messageCode == 200) {
          let Arr = data.messageContent || []
          for (var i = 0; i < Arr.length; i++) {
            var itemObj = {
              label: Arr[i].modelName,
              value: Arr[i].modelId,
              type: type
            }
            if (type === 5) {
              this.terminaloptionA.push(itemObj)
            } else {
              this.terminaloption.push(itemObj)
            }
          }

          console.log(this.terminaloption)
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 中继设备型号
    repeaterTerminalselect() {
      console.log(111111111)
      this.$http({
        url: this.$http.adornUrl('/terminal/terminal-model-select'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            terminalType: 30,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data)
        if (data.messageCode == 200) {
          let Arr = data.messageContent
          if (this.repeaterTerminaloption.length == 0) {
            for (var i = 0; i < Arr.length; i++) {
              var itemObj = {
                label: Arr[i].modelName,
                value: Arr[i].modelId,
                type: 30
              }
              this.repeaterTerminaloption.push(itemObj)
            }
            console.log(this.repeaterTerminaloption)
          }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //树状回调id
    setid(val) {
      this.callbackid = val
    },

    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex
    },
    // 折叠面板每次只能展开一行
    expandSelect(row, expandedRows) {
      this.relaylist = this.controllerBuildingRequestListArr[
        row.index
      ].terminalRepeaterResponseList
      this.gatewayindex = row.index
      this.expandRow = row
      var that = this
      if (expandedRows.length) {
        that.expands = []
        if (row) {
          that.expands.push(row.index) // 每次push进去的是每行的ID
        }
      } else {
        that.expands = [] // 默认不展开
      }
    },
    // 新增删除网关
    deletegateway(index) {
      this.$confirm('此操作将永久删除该网关, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.controllerBuildingRequestListArr.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 修改删除网关
    editdeletegateway(index) {
      this.$confirm('此操作将永久删除该网关, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.controllerBuildingRequestListArr.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 新增和修改楼栋的  --- 添加网关
    controlladdbuildingFormSubmit() {
      this.$refs['controllerBuildingRequestList'].validate(valid => {
        if (valid) {
          let newObj = {}
          // 网关类型
          newObj.controllerType = this.controllerBuildingRequestList.controllerType
          // 有线网关没有信道号
          newObj.channel =
            this.controllerBuildingRequestList.controllerType == 1
              ? this.controllerBuildingRequestList.channel
              : ''
          newObj.controllerName = this.controllerBuildingRequestList.controllerName
          newObj.ip = this.controllerBuildingRequestList.ip
          newObj.port = this.controllerBuildingRequestList.port
          newObj.position = this.controllerBuildingRequestList.position

          newObj.controllerModel = this.controllerBuildingRequestList.controllerModel
          newObj.wirelessPower = this.controllerBuildingRequestList.wirelessPower
          // 有线网关没有无线功率
          newObj.firmwareVersion =
            this.controllerBuildingRequestList.controllerType == 1
              ? this.controllerBuildingRequestList.firmwareVersion
              : ''
          newObj.isUse = this.controllerBuildingRequestList.isUse
          console.log(newObj)

          newObj.terminalRepeaterResponseList = []
          this.controllerBuildingRequestListArr.push(newObj)
          this.$refs['controllerBuildingRequestList'].resetFields()
          this.innerVisible = false
        }
      })
    },
    controllercloseDialog(done) {
      this.$refs['controllerBuildingRequestList'].resetFields()
      done()
    },
    eidtcontrollercloseDialog(done) {
      this.$refs['editcontrollerBuildingRequestList'].resetFields()
      done()
    },
    eidtcontrolladdbuildingvisible() {
      this.eidtinnerVisible = false
      this.$refs['editcontrollerBuildingRequestList'].resetFields()
    },
    addcontrollercloseDialog(done) {
      this.$refs['addcontrollerBuildingRequestList'].resetFields()
      done()
    },

    addcontrolladdbuildingvisible() {
      this.addinnerVisible = false
    },
    // 添加中继
    repeateraddgateway(row, index) {
      console.log(row)
      this.gatewayindex = index
      let repeaterTerminaloption1 = [
        {
          value: 110,
          label: 'WE1600'
        },
        {
          value: 111,
          label: 'WE1611'
        }
      ]
      let repeaterTerminaloption2 = [
        {
          value: 111,
          label: 'WE1611'
        },
        {
          value: 112,
          label: 'WE1620'
        }
      ]
      let repeaterTerminaloption3 = [
        {
          value: 112,
          label: 'WE1620'
        }
      ]
      if (row.controllerModel == 91 || row.controllerModel == 92) {
        this.repeaterTerminaloption = repeaterTerminaloption1
      } else if (row.controllerModel == 96) {
        this.repeaterTerminaloption = repeaterTerminaloption2
      } else if (row.controllerModel == 98) {
        this.repeaterTerminaloption = repeaterTerminaloption3
      }
      this.repeaterinnerVisible = true
    },
    // 修改楼栋 --编辑网关
    editrepeateraddgateway(row) {
      console.log(row)
      this.gatewayindex = row.index
      this.editcontrollerBuildingRequestList.controllerType = row.controllerType
      this.editcontrollerBuildingRequestList.channel = row.channel
      this.editcontrollerBuildingRequestList.controllerName = row.controllerName
      this.editcontrollerBuildingRequestList.ip = row.ip
      this.editcontrollerBuildingRequestList.port = row.port
      this.editcontrollerBuildingRequestList.position = row.position

      this.editcontrollerBuildingRequestList.controllerModel =
        row.controllerModel
      this.editcontrollerBuildingRequestList.wirelessPower = row.wirelessPower
      this.editcontrollerBuildingRequestList.firmwareVersion =
        row.firmwareVersion
      this.editcontrollerBuildingRequestList.isUse =
        row.isUse == 1 ? true : false
      // 获取设备型号
      this.terminaloption = []
      if (row.controllerType == 1) {
        this.terminalselect(1)
      } else if (row.controllerType == 2) {
        this.terminalselect(2)
      }
      this.eidtinnerVisible = true
    },
    // 新增楼栋 --编辑网关
    addrepeateraddgateway(row) {
      console.log(row)
      this.gatewayindex = row.index
      this.addcontrollerBuildingRequestList.controllerType = row.controllerType
      this.addcontrollerBuildingRequestList.channel = row.channel
      this.addcontrollerBuildingRequestList.controllerName = row.controllerName
      this.addcontrollerBuildingRequestList.ip = row.ip
      this.addcontrollerBuildingRequestList.port = row.port
      this.addcontrollerBuildingRequestList.position = row.position

      this.addcontrollerBuildingRequestList.controllerModel =
        row.controllerModel
      this.addcontrollerBuildingRequestList.wirelessPower = row.wirelessPower
      this.addcontrollerBuildingRequestList.firmwareVersion =
        row.firmwareVersion
      this.addcontrollerBuildingRequestList.isUse = row.isUse
      // 获取设备型号
      this.terminaloption = []
      if (row.controllerType == 1) {
        this.terminalselect(1)
      } else if (row.controllerType == 2) {
        this.terminalselect(2)
      }
      this.addinnerVisible = true
    },
    eidtcontrolladdbuildingFormSubmit() {
      this.$refs['editcontrollerBuildingRequestList'].validate(valid => {
        if (valid) {
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].controllerName = this.editcontrollerBuildingRequestList.controllerName
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].channel = this.editcontrollerBuildingRequestList.channel
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].ip = this.editcontrollerBuildingRequestList.ip
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].port = this.editcontrollerBuildingRequestList.port
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].position = this.editcontrollerBuildingRequestList.position

          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].controllerModel = this.editcontrollerBuildingRequestList.controllerModel
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].wirelessPower = this.editcontrollerBuildingRequestList.wirelessPower
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].firmwareVersion = this.editcontrollerBuildingRequestList.firmwareVersion

          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].isUse = this.editcontrollerBuildingRequestList.isUse
          this.eidtinnerVisible = false
        }
      })
    },
    // 新增网关时的修改
    addcontrolladdbuildingFormSubmit() {
      this.$refs['addcontrollerBuildingRequestList'].validate(valid => {
        if (valid) {
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].controllerName = this.addcontrollerBuildingRequestList.controllerName
          // 网关类型
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].controllerType = this.addcontrollerBuildingRequestList.controllerType
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].channel = this.addcontrollerBuildingRequestList.channel
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].ip = this.addcontrollerBuildingRequestList.ip
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].port = this.addcontrollerBuildingRequestList.port
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].position = this.addcontrollerBuildingRequestList.position

          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].controllerModel = this.addcontrollerBuildingRequestList.controllerModel
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].wirelessPower = this.addcontrollerBuildingRequestList.wirelessPower
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].firmwareVersion = this.addcontrollerBuildingRequestList.firmwareVersion
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].isUse = this.addcontrollerBuildingRequestList.isUse

          console.log(this.controllerBuildingRequestListArr)
          this.addinnerVisible = false
        }
      })
    },
    repeatercontrolladdbuildingvisible() {
      this.repeaterinnerVisible = false
      // this.$refs["crepeaterid"].resetFields();
      this.Ztitle = '新增中继'
      this.crepeaterid = {
        repeaterid: '',
        terminalName: '',
        terminalModel: '',
        isUse: true
      }
    },
    repeatercontrollercloseDialog(done) {
      // this.$refs["crepeaterid"].resetFields();
      this.Ztitle = '新增中继'

      this.crepeaterid = {
        repeaterid: '',
        terminalName: '',
        terminalModel: '',
        isUse: true
      }
      done()
    },
    // 中继编辑
    edittegateway(val, index) {
      // this.repeaterinnerVisible = true;
      this.isEdit = true
      this.Zindex = index
      this.Ztitle = '编辑中继'
      this.repeateraddgateway(this.expandRow, this.expandRow.index)
      this.crepeaterid = {
        ...val,
        isUse: val.isUse == 0 ? false : true,
        repeaterid: val.terminalCode
      }

      console.log(this.gatewayindex)
      console.log(this.expandRow)
      console.log(val, index)
      // this.controllerBuildingRequestListArr[
      //       this.gatewayindex
      //     ].terminalRepeaterResponseList[index].isUse = 0
    },
    repeatereletegateway(val, index) {
      this.$confirm('此操作将永久删除该中继, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.controllerBuildingRequestListArr[
            this.gatewayindex
          ].terminalRepeaterResponseList.splice(index, 1)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 添加确定
    repeatercontrolladdbuildingFormSubmit() {
      this.Ztitle = '新增中继'
      if (this.isEdit) {
        this.controllerBuildingRequestListArr[
          this.gatewayindex
        ].terminalRepeaterResponseList[this.Zindex].isUse = this.crepeaterid
          .isUse
          ? 1
          : 0
        this.controllerBuildingRequestListArr[
          this.gatewayindex
        ].terminalRepeaterResponseList[
          this.Zindex
        ].terminalCode = this.crepeaterid.repeaterid
        this.controllerBuildingRequestListArr[
          this.gatewayindex
        ].terminalRepeaterResponseList[
          this.Zindex
        ].terminalModel = this.crepeaterid.terminalModel
        this.controllerBuildingRequestListArr[
          this.gatewayindex
        ].terminalRepeaterResponseList[
          this.Zindex
        ].terminalName = this.crepeaterid.terminalName
        //中继编号
        this.crepeaterid = {
          repeaterid: '',
          terminalName: '',
          terminalModel: '',
          isUse: true
        }
        this.isEdit = false
        this.repeaterinnerVisible = false
      } else {
        this.$refs['crepeaterid'].validate(valid => {
          if (valid) {
            this.controllerBuildingRequestListArr[
              this.gatewayindex
            ].terminalRepeaterResponseList.push({
              terminalModel: this.crepeaterid.terminalModel,
              isUse: this.crepeaterid.isUse ? 1 : 0,
              terminalCode: this.crepeaterid.repeaterid,
              terminalName: this.crepeaterid.terminalName
            })
            this.$refs['crepeaterid'].resetFields()
            this.repeaterinnerVisible = false
            console.log(
              this.controllerBuildingRequestListArr[0]
                .terminalRepeaterResponseList
            )
          }
        })
      }
    },
    controlladdbuildingvisible() {
      this.innerVisible = false
      this.$refs['controllerBuildingRequestList'].resetFields()
    },
    //新增区域与楼栋
    closeDialog(done) {
      this.$refs['addataForm'].resetFields()
      done()
    },
    editcloseDialog(done) {
      this.editataForm.regionprincipalarr = []
      this.$refs['editataForm'].resetFields()
      done()
    },
    addvisible() {
      this.addDialogFormVisible = false
      this.$refs['addataForm'].resetFields()
    },
    addataFormSubmit() {
      this.$refs['addataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/area/room/add-area-info'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                areaName: this.addataForm.areaName,
                remark: this.addataForm.remark,
                superiorAreaGuid: this.addataForm.superiorAreaGuid,
                unitGuid: this.unitGuid,
                userGuidList: this.addataForm.regionprincipalarr
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                message: '新增成功',
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.addDialogFormVisible = false
                  this.$emit('refreshDataList')
                }
              })
              this.$refs['addataForm'].resetFields()
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    addinit() {
      this.superiorAreaGuidlist = this.arealsit
      this.addDialogFormVisible = true
    },

    // 楼栋新增
    closeDialogbuilding(done) {
      this.gatewayindex = ''
      this.controllerBuildingRequestListArr = []
      this.$refs['addbuilding'].resetFields()
      done()
    },
    editcloseDialogbuilding(done) {
      this.eidtbuilding.regionprincipalarr = []
      this.$refs['eidtbuilding'].clearValidate()
      done()
    },
    //添加网关
    addgateway() {
      this.innerVisible = true
      this.terminaloption = []
      this.controllerBuildingRequestList.port = 4001;
      this.$set(this.controllerBuildingRequestList, 'position', '')
      console.log(this.controllerBuildingRequestList)
      this.$nextTick(() => {
        this.$refs['controllerBuildingRequestList'].resetFields()
        this.terminalselect(1)
      })
    },
    addinitbuilding(val) {
      if (val != '' && val !== null) {
        this.addbuilding.areaGuid = val
      }
      this.controllerBuildingRequestListArr = []
      this.relaylist = []
      this.buildingsuperiorAreaGuidlist = []
      this.arealsit.map(item => {
        if (item.value != '') {
          this.buildingsuperiorAreaGuidlist.push(item)
        }
      })
      this.addbuildingDialogFormVisible = true
    },
    addbuildingvisible() {
      this.gatewayindex = ''
      this.addbuildingDialogFormVisible = false
      this.addbuilding.areaGuid = ''
      this.controllerBuildingRequestListArr = []
      this.$refs['addbuilding'].resetFields()
    },
    addbuildingFormSubmit() {
      this.$refs['addbuilding'].validate(valid => {
        if (valid) {
          let controllerBuildingRequestListArr = JSON.parse(
            JSON.stringify(this.controllerBuildingRequestListArr)
          )
          if (controllerBuildingRequestListArr.length != 0) {
            controllerBuildingRequestListArr.map(
              item => (item.isUse = item.isUse ? 1 : 0)
            )
          }
          console.log(controllerBuildingRequestListArr)
          this.$http({
            url: this.$http.adornUrl('/area/room/add-building-info'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                buildingCode: this.addbuilding.buildingCode,
                buildingName: this.addbuilding.buildingName,
                floors: this.addbuilding.floors,
                unitGuid: this.unitGuid,
                areaGuid: this.addbuilding.areaGuid,
                controllerBuildingRequestList: controllerBuildingRequestListArr,
                userGuidList: this.addbuilding.regionprincipalarr
              },
              messageType: 0
            })
          }).then(({ data }) => {
            console.log(data)
            if (data.messageCode == 200) {
              this.$message({
                message: '新增成功',
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.addbuildingDialogFormVisible = false
                  this.$emit('refreshDataList')
                  this.$emit('editbuldinglist', this.addbuilding.areaGuid)
                }
              })
              this.$refs['addbuilding'].resetFields()
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    //修改区域与楼栋
    eidtinit(node, data) {
      console.log(data)
      this.editataForm.areaName = data.label
      this.editataForm.superiorAreaGuid = node.parent.data.name
      this.editataForm.areaGuid = data.name
      this.editsuperiorAreaGuidlist = []
      this.getmangeruser(data)
      this.$http({
        url: this.$http.adornUrl('/area/room/area-not-children'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            areaGuid: data.name,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        // console.log(data)
        if (data.messageCode == 200) {
          let Arr = data.messageContent
          if (this.editsuperiorAreaGuidlist.length == 0) {
            for (var i = 0; i < Arr.length; i++) {
              var itemObj = {
                label: Arr[i].areaName,
                value: Arr[i].areaGuid
              }
              this.editsuperiorAreaGuidlist.push(itemObj)
            }
          }
          this.$nextTick(() => {
            this.editDialogFormVisible = true
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //获取区域管理员信息
    getmangeruser(data) {
      this.editataForm.regionprincipalarr = []
      this.$http({
        url: this.$http.adornUrl('/area/room/area-manager-user'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            areaGuid: data.name,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          for (var i = 0; i < data.messageContent.length; i++) {
            this.editataForm.regionprincipalarr.push(
              data.messageContent[i].userGuid
            )
          }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    editvisible() {
      this.editDialogFormVisible = false
      this.$refs['editataForm'].resetFields()
      this.editataForm.regionprincipalarr = []
    },
    //修改区域信息
    editataFormSubmit() {
      this.$refs['editataForm'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl('/area/room/update-area-info'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                areaGuid: this.editataForm.areaGuid,
                areaName: this.editataForm.areaName,
                superiorAreaGuid: this.editataForm.superiorAreaGuid,
                unitGuid: this.unitGuid,
                userGuidList: this.editataForm.regionprincipalarr
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                message: '添加成功',
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList', this.callbackid)
                }
              })
              this.editDialogFormVisible = false
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    //区域更新下拉框信息
    //楼层详细信息
    eidtinitbuilding(val, id) {
      this.relaylist = []
      this.controllerBuildingRequestListArr = []
      if (val.name != undefined) {
        this.editbuildingGuid = val.name
      }
      if (val.buildingGuid != undefined) {
        this.editbuildingGuid = val.buildingGuid
      }
      console.log(this.editbuildingGuid,       111111111111)
      this.gebuldingmangeruser(val)
      this.$http({
        url: this.$http.adornUrl('/area/room/building-details'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            buildingGuid: this.editbuildingGuid,
            unitGuid: id
          },
          messageType: 0
        })
      }).then(({ data }) => {
        console.log(data)
        if (data.messageCode == 200) {
          this.eidtbuilding.areaGuid = data.messageContent.areaGuid
          this.eidtbuilding.buildingName = data.messageContent.buildingName
          this.eidtbuilding.buildingGuid = data.messageContent.buildingGuid
          this.eidtbuilding.buildingCode = data.messageContent.buildingCode
          this.eidtbuilding.floors = data.messageContent.floors
          this.controllerBuildingRequestListArr =
            data.messageContent.controllerList
          this.editbuildingsuperiorAreaGuidlist = []
          // 清除最顶层
          this.arealsit.map(item => {
            if (item.value != '') {
              this.editbuildingsuperiorAreaGuidlist.push(item)
            }
          })
          this.editbuildingDialogFormVisible = true
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //获取楼栋管理员信息
    gebuldingmangeruser(val) {
      this.eidtbuilding.regionprincipalarr = []
      this.$http({
        url: this.$http.adornUrl('/area/room/building-manager-user'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            buildingGuid: val.name,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        // console.log(data)
        if (data.messageCode == 200) {
          for (var i = 0; i < data.messageContent.length; i++) {
            this.eidtbuilding.regionprincipalarr.push(
              data.messageContent[i].userGuid
            )
          }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    eidtbuildingvisible() {
      this.editbuildingDialogFormVisible = false
      this.$refs['eidtbuilding'].clearValidate()
      this.eidtbuilding.regionprincipalarr = []
    },
    eidtbuildingFormSubmit() {
      //  console.log(this.controllerBuildingRequestListArr)
      this.$refs['eidtbuilding'].validate(valid => {
        if (valid) {
          let controllerBuildingRequestListArr = JSON.parse(
            JSON.stringify(this.controllerBuildingRequestListArr)
          )
          if (controllerBuildingRequestListArr.length != 0) {
            controllerBuildingRequestListArr.map(
              item => (item.isUse = item.isUse ? 1 : 0)
            )
          }
          console.log(controllerBuildingRequestListArr)
          this.$http({
            url: this.$http.adornUrl('/area/room/update-building-info'),
            method: 'post',
            data: this.$http.adornData({
              messageContent: {
                areaGuid: this.eidtbuilding.areaGuid,
                buildingCode: this.eidtbuilding.buildingCode,
                buildingName: this.eidtbuilding.buildingName,
                floors: this.eidtbuilding.floors,
                unitGuid: this.unitGuid,
                buildingGuid: this.eidtbuilding.buildingGuid,
                controllerBuildingRequestList: controllerBuildingRequestListArr,
                userGuidList: this.eidtbuilding.regionprincipalarr
              },
              messageType: 0
            })
          }).then(({ data }) => {
            if (data.messageCode == 200) {
              this.$message({
                message: '修改成功',
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.editbuildingDialogFormVisible = false
                  //  this.$emit('refreshDataList')
                  this.$emit('refreshDataList', this.callbackid)
                  this.$emit('editbuldinglist', this.eidtbuilding.areaGuid)
                }
              })
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    delebulding(id, areaid) {
      // this.callbackdemo=demo
      this.$confirm('此操作将永久删除该楼栋, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.delebuldinginit(id, areaid)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    delebuldinginit(id, areaid) {
      this.$http({
        url: this.$http.adornUrl('/area/room/delete-building-info'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            buildingGuid: id,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            type: 'success',
            message: '删除成功!',
            duration: 500,
            onClose: () => {
              this.$emit('refreshDataList')
              this.$emit('editbuldinglist', areaid)
            }
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    //删除区域
    deletarea(id) {
      this.$confirm('此操作将永久删除该区域, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deletareainit(id)
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    deletareainit(id) {
      this.$http({
        url: this.$http.adornUrl('/area/room/delete-area-info'),
        method: 'post',
        data: this.$http.adornData({
          messageContent: {
            areaGuid: id,
            unitGuid: this.unitGuid
          },
          messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode == 200) {
          this.$message({
            type: 'success',
            message: '删除成功!',
            duration: 500,
            onClose: () => {
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-form {
  /deep/.el-form-item {
    margin-bottom: 10px;
  }
  .el-radio {
    margin-right: 10px;
  }
}
// 弹窗显示
/deep/.el-dialog__wrapper .el-dialog .el-dialog__body {
  padding: 10px;
}
.add_update_building {
  // 弹窗显示
  /deep/.el-dialog--center .el-dialog__body {
    padding: 10px 30px;
  }
  /deep/.el-form-item {
    margin-bottom: 10px;
  }

  //滚动条的宽度
  ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
  }

  //滚动条的滑块
  ::-webkit-scrollbar-thumb {
    background-color: #a1a3a9;
    border-radius: 3px;
  }

  height: 100%;
  .table thead tr {
    display: block;
  }
  .table tbody {
    display: block;
    height: 200px;
    overflow: auto;
  }
  .table th {
    width: 20%;
  }
  .table tr {
    height: 20%;
  }
  .table td {
    width: 1%;
    border-top: 0px;
    border-right: 0px;
    border-left: 0px;
  }
  .colorindex {
    background-color: #67c23a;
    color: white;
  }
  //  .el-table__expanded-cell[class*=cell]{
  //    background-color: #eaeefb !important;
  //   }
}
</style>